﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Messaging;
namespace messageClientLib
{
    public class mainProgram
    {
        MessageQueue messageQueue = null;
        const string pathQueue = @".\Private$\PortQueue";

        public mainProgram()
        {
            if (MessageQueue.Exists(pathQueue))
                messageQueue = new MessageQueue(pathQueue);
            else
                messageQueue = MessageQueue.Create(pathQueue);
        }
        public void receive()
        {
            System.Messaging.Message mss = new System.Messaging.Message();
            int i = 1;
            try
            {
               mss = messageQueue.Receive();

               mss.Formatter = new XmlMessageFormatter(
                        new String[] { "System.String" });
                
               Console.WriteLine("stt" + i + mss.Label.ToString() + "---" + mss.Body.ToString());
               
            }                                                                                                                                          
            catch (Exception e)
            {
               Console.WriteLine(e.Message);
            }
        }
    }
}
